package nfwx.analytics;

import java.util.Date;

/**
 * 应用使用事件
 */

public class GrabAppUseEvent extends GrabAppEvent {

    final GrabAPPSession _session;
    private boolean _finish;
    GrabAppUseEvent(GrabAPPSession session, String entity)
    {
        super(EVENT_NAME_APP_USE);
        _session = session;
        this.entity.setValue(entity);
    }

    /**
     * 获取自定义的附加数据
     * @return
     */
    GrabObject getExtra()
    {
        return extra;
    }

    /**
     * 完成事件并提交
     */
    public void finish()
    {
        if (_finish) return;
        _finish = true;
        if (_session.getEnded()) return;
        double t = (new Date()).getTime();
        this.duration.setValue(t - this.time.getValue());
        _session.events.push(this);
    }
}
